{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_json('./data/dbmovies.json')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>url</th>\n",
       "      <th>cover</th>\n",
       "      <th>rate</th>\n",
       "      <th>director</th>\n",
       "      <th>composer</th>\n",
       "      <th>actor</th>\n",
       "      <th>category</th>\n",
       "      <th>district</th>\n",
       "      <th>language</th>\n",
       "      <th>showtime</th>\n",
       "      <th>length</th>\n",
       "      <th>othername</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>25746375</td>\n",
       "      <td>我是路人甲</td>\n",
       "      <td>http://movie.douban.com/subject/25746375/</td>\n",
       "      <td>http://img3.douban.com/view/movie_poster_cover...</td>\n",
       "      <td>7.4</td>\n",
       "      <td>[尔冬升]</td>\n",
       "      <td>[尔冬升]</td>\n",
       "      <td>[万国鹏, 王婷, 沈凯, 徐小琴, 林晨, 魏星, 蒿怡帆, 蒿怡菲, 覃培军, 王昭, ...</td>\n",
       "      <td>[剧情, 喜剧]</td>\n",
       "      <td>[China_中国大陆]</td>\n",
       "      <td>[汉语普通话, 粤语, 浙江方言]</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>134.0</td>\n",
       "      <td>[I Am Somebody]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5446197</td>\n",
       "      <td>铁拳</td>\n",
       "      <td>http://movie.douban.com/subject/5446197/</td>\n",
       "      <td>http://img3.douban.com/view/movie_poster_cover...</td>\n",
       "      <td>7.1</td>\n",
       "      <td>[安东尼·福奎阿]</td>\n",
       "      <td>[科特·萨特]</td>\n",
       "      <td>[杰克·吉伦哈尔, 福里斯特·惠特克, 瑞秋·麦克亚当斯, 娜奥米·哈里斯, 50分, 乌娜...</td>\n",
       "      <td>[剧情, 动作, 运动]</td>\n",
       "      <td>[United States of America_美国, China_中国大陆]</td>\n",
       "      <td>[英语]</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>123.0</td>\n",
       "      <td>[左撇子, 震撼擂台(台), 再战击情(港)]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>25885212</td>\n",
       "      <td>我们梦中见</td>\n",
       "      <td>http://movie.douban.com/subject/25885212/</td>\n",
       "      <td>http://img4.douban.com/view/movie_poster_cover...</td>\n",
       "      <td>7.6</td>\n",
       "      <td>[布雷特·海利]</td>\n",
       "      <td>[Marc Basch, 布雷特·海利]</td>\n",
       "      <td>[布莱思·丹纳, 马丁·斯塔尔, 琼·斯奎布, 雷亚·普尔曼, 玛丽·凯·普莱斯, 玛琳·阿...</td>\n",
       "      <td>[剧情, 喜剧]</td>\n",
       "      <td>[United States of America_美国]</td>\n",
       "      <td>[英语]</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>92.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         id  title                                        url  \\\n",
       "0  25746375  我是路人甲  http://movie.douban.com/subject/25746375/   \n",
       "1   5446197     铁拳   http://movie.douban.com/subject/5446197/   \n",
       "2  25885212  我们梦中见  http://movie.douban.com/subject/25885212/   \n",
       "\n",
       "                                               cover  rate   director  \\\n",
       "0  http://img3.douban.com/view/movie_poster_cover...   7.4      [尔冬升]   \n",
       "1  http://img3.douban.com/view/movie_poster_cover...   7.1  [安东尼·福奎阿]   \n",
       "2  http://img4.douban.com/view/movie_poster_cover...   7.6   [布雷特·海利]   \n",
       "\n",
       "               composer                                              actor  \\\n",
       "0                 [尔冬升]  [万国鹏, 王婷, 沈凯, 徐小琴, 林晨, 魏星, 蒿怡帆, 蒿怡菲, 覃培军, 王昭, ...   \n",
       "1               [科特·萨特]  [杰克·吉伦哈尔, 福里斯特·惠特克, 瑞秋·麦克亚当斯, 娜奥米·哈里斯, 50分, 乌娜...   \n",
       "2  [Marc Basch, 布雷特·海利]  [布莱思·丹纳, 马丁·斯塔尔, 琼·斯奎布, 雷亚·普尔曼, 玛丽·凯·普莱斯, 玛琳·阿...   \n",
       "\n",
       "       category                                   district           language  \\\n",
       "0      [剧情, 喜剧]                               [China_中国大陆]  [汉语普通话, 粤语, 浙江方言]   \n",
       "1  [剧情, 动作, 运动]  [United States of America_美国, China_中国大陆]               [英语]   \n",
       "2      [剧情, 喜剧]              [United States of America_美国]               [英语]   \n",
       "\n",
       "   showtime  length                othername  \n",
       "0    2015.0   134.0          [I Am Somebody]  \n",
       "1    2015.0   123.0  [左撇子, 震撼擂台(台), 再战击情(港)]  \n",
       "2    2015.0    92.0                     None  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###### 实体类型（entity）：电影、人名、电影类型、年份、地区、语言\n",
    "###### 电影属性：名字、id、时长、url、豆瓣评分\n",
    "###### 人物属性：id </br></br>\n",
    "\n",
    "###### 实体-实体 关系：\n",
    "###### 电影-导演-人名\n",
    "###### 电影-编剧-人名\n",
    "###### 电影-演员-人名\n",
    "###### 电影-类型-电影类型\n",
    "###### 电影-上映时间-年份\n",
    "###### 电影-上映地点-地点\n",
    "\n",
    "###### 实体-属性 关系：\n",
    "\n",
    "###### 电影-id-id\n",
    "###### 电影-豆瓣评分-分数\n",
    "###### 电影-网址-url\n",
    "\n",
    "###### 人名-id-id\n",
    "\n",
    "###### 电影类型-id-id\n",
    "\n",
    "###### 年份-id-id\n",
    "\n",
    "###### 地区-id-id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['我是路人甲',\n",
       " '铁拳',\n",
       " '我们梦中见',\n",
       " '少年透明人',\n",
       " '撒迦利亚',\n",
       " '非我',\n",
       " '唇上之歌',\n",
       " '如晴天，似雨天',\n",
       " '故事的故事',\n",
       " '奸臣',\n",
       " '头脑特工队',\n",
       " '小森林 冬春篇',\n",
       " '小男孩',\n",
       " '可爱的你',\n",
       " '花与爱丽丝杀人事件',\n",
       " '百元之恋',\n",
       " '少年班',\n",
       " '末日崩塌',\n",
       " '深夜食堂 电影版',\n",
       " '冲出康普顿',\n",
       " '魔力麦克2',\n",
       " '谜城',\n",
       " '模仿游戏',\n",
       " '小羊肖恩',\n",
       " '进击的巨人真人版：前篇',\n",
       " '女间谍',\n",
       " '爆裂鼓手',\n",
       " '杀破狼2',\n",
       " '道士下山',\n",
       " '我是谁：没有绝对安全的系统',\n",
       " '贝利叶一家',\n",
       " '疯狂的麦克斯4：狂暴之路',\n",
       " '时光尽头的恋人',\n",
       " '坏姐姐之拆婚联盟',\n",
       " '嘘！禁止想象！',\n",
       " '机械姬',\n",
       " '栀子花开',\n",
       " '复仇者联盟2：奥创纪元',\n",
       " '工作女郎',\n",
       " '少女哪吒',\n",
       " '我的个神啊',\n",
       " '左耳',\n",
       " '对风说爱你',\n",
       " '小时代4：灵魂尽头',\n",
       " '消失的爱人',\n",
       " '暗黑之地',\n",
       " '麦克法兰',\n",
       " '风流艳妇',\n",
       " '念念',\n",
       " '速度与激情7',\n",
       " '王牌特工：特工学院',\n",
       " '泰迪熊2',\n",
       " '远离尘嚣',\n",
       " '新步步惊心',\n",
       " '国际市场',\n",
       " '重返20岁',\n",
       " '分歧者2：绝地反击',\n",
       " '最长的旅程',\n",
       " '阿罗哈',\n",
       " '暴疯语',\n",
       " '美国狙击手',\n",
       " '味园Universe',\n",
       " '寄生兽',\n",
       " '中国之旅',\n",
       " '疯狂外星人',\n",
       " '控制游戏',\n",
       " '超能查派',\n",
       " '所罗门的伪证前篇：事件',\n",
       " '星际穿越',\n",
       " '天将雄师',\n",
       " '冲锋车',\n",
       " '霍比特人3：五军之战',\n",
       " '金衣女人',\n",
       " '无人引航',\n",
       " '侏罗纪世界',\n",
       " '帕丁顿熊',\n",
       " '超能陆战队',\n",
       " '赤道',\n",
       " '有一个地方只有我们知道',\n",
       " '男人与鸡',\n",
       " '博物馆奇妙夜3',\n",
       " '44号孩子',\n",
       " '万物生长',\n",
       " '0.5毫米',\n",
       " '鸭王',\n",
       " '战狼',\n",
       " '爱你，罗茜',\n",
       " '江南1970',\n",
       " '第七子：降魔之战',\n",
       " '军犬麦克斯',\n",
       " '一步之遥',\n",
       " '生活残骸',\n",
       " '海月姬',\n",
       " '雏妓',\n",
       " '灰姑娘',\n",
       " '横冲直撞好莱坞',\n",
       " '涉足荒野',\n",
       " '所罗门的伪证后篇：审判',\n",
       " '命中注定',\n",
       " '何以笙箫默',\n",
       " '许三观',\n",
       " '午夜邂逅',\n",
       " '贵族大盗',\n",
       " '智取威虎山',\n",
       " '木星上行',\n",
       " '我是女王',\n",
       " '爱的那点性事',\n",
       " '西部慢调',\n",
       " '暴走神探',\n",
       " '客人',\n",
       " '完美音调2',\n",
       " '饥饿游戏3：嘲笑鸟(上)',\n",
       " '二十',\n",
       " '失孤',\n",
       " '坚不可摧',\n",
       " '测试',\n",
       " '七日地狱',\n",
       " '明星伙伴',\n",
       " '钟馗伏魔：雪妖魔灵',\n",
       " '太平轮(上)',\n",
       " '少数意见',\n",
       " '爱情限时恋未尽',\n",
       " '十万个冷笑话',\n",
       " '海绵宝宝历险记：海绵出水',\n",
       " '狂怒',\n",
       " '长寿商会',\n",
       " '飓风营救3',\n",
       " '要听神明的话',\n",
       " '缄默的迷宫',\n",
       " '通灵之六世古宅',\n",
       " '北京纽约',\n",
       " '我们假期做了什么',\n",
       " '伸冤人',\n",
       " '焦点',\n",
       " '新女友',\n",
       " '鬼牌游戏',\n",
       " '大眼睛',\n",
       " '小混乱',\n",
       " '麦兜我和我妈妈',\n",
       " '珍妮的婚礼',\n",
       " '咱们结婚吧',\n",
       " '冲上云霄',\n",
       " '匆匆那年',\n",
       " '塞尔玛',\n",
       " '法老与众神',\n",
       " '魔法黑森林',\n",
       " '1944',\n",
       " '烈性摔跤',\n",
       " '再见我们的十年',\n",
       " '法国战恋曲',\n",
       " '微爱之渐入佳境',\n",
       " '真幌站前狂想曲',\n",
       " '青春之旅 真人版',\n",
       " '潜伏3',\n",
       " '布拉芙夫人',\n",
       " '花宵道中',\n",
       " '移动迷宫',\n",
       " '暗夜逐仇',\n",
       " '生命之书',\n",
       " '近距离恋爱',\n",
       " '真实故事',\n",
       " '纸之月',\n",
       " '性本恶',\n",
       " '有种你爱我',\n",
       " '浪客剑心：传说的完结篇',\n",
       " '玩命警车',\n",
       " '丹尼·科林斯',\n",
       " '涉外大饭店2',\n",
       " '高手们',\n",
       " '不死鸟',\n",
       " '马达加斯加的企鹅',\n",
       " '乐高DC超级英雄：正义联盟之末日军团的进攻',\n",
       " '鞋匠人生',\n",
       " '人体蜈蚣3',\n",
       " '朝我心脏开枪',\n",
       " '12金鸭',\n",
       " '哥本哈根',\n",
       " '年鉴计划',\n",
       " '女孩闺房',\n",
       " '寄生兽：完结篇',\n",
       " '撒娇女人最好命',\n",
       " '娚的一生',\n",
       " '疾速追杀',\n",
       " '阁楼',\n",
       " '正义联盟：神魔之战',\n",
       " '白幽灵传奇之绝命逃亡',\n",
       " '女狙击手',\n",
       " '封门诡影',\n",
       " '恋爱的味道',\n",
       " '全力扣杀',\n",
       " '死亡录像4：启示录',\n",
       " '沼泽地',\n",
       " '深夜前的五分钟',\n",
       " '极秘搜查',\n",
       " '隐秘的诱惑',\n",
       " '魁拔Ⅲ战神崛起',\n",
       " '偷狗的完美方法',\n",
       " '别惹德州',\n",
       " '一万年以后',\n",
       " '一路惊喜',\n",
       " '我的早更女友',\n",
       " '露水红颜',\n",
       " '京城学校：消失的少女们',\n",
       " '福福庄的阿福',\n",
       " '年轻母亲3：我年纪如何',\n",
       " '恋爱排班表',\n",
       " '定制伴郎',\n",
       " '男人不可以穷',\n",
       " '熊出没之雪岭熊风',\n",
       " '至暴之年',\n",
       " '狱前教育',\n",
       " '不能说的夏天',\n",
       " '举报者',\n",
       " '名侦探柯南：江户川柯南失踪事件～史上最惨的两天～',\n",
       " '延坪海战',\n",
       " '骇客交锋',\n",
       " '去见瀑布',\n",
       " '小野寺姐弟',\n",
       " '垃圾男孩',\n",
       " '脑浆炸裂少女',\n",
       " '一个人的武林',\n",
       " '黄飞鸿之英雄有梦',\n",
       " '单身男女2',\n",
       " '勃艮第公爵',\n",
       " 'X射线营地',\n",
       " '恶魔',\n",
       " '奔跑者',\n",
       " '安娜贝尔',\n",
       " '速度超越激情',\n",
       " '机动战士高达 THE ORIGIN I 青瞳的卡斯巴尔',\n",
       " '恶老板2',\n",
       " '德古拉元年',\n",
       " '黎明的沙耶',\n",
       " '阿呆与阿瓜2',\n",
       " '占水师',\n",
       " '平行宇宙',\n",
       " '罪恶的编年史',\n",
       " '永远十六岁',\n",
       " '青春誓约',\n",
       " '机器纪元',\n",
       " '第28年的甲子园',\n",
       " '赛琳娜',\n",
       " '不速之客',\n",
       " '最好的我',\n",
       " '安妮：纽约奇缘',\n",
       " '人艰不拆',\n",
       " '我的爱我的新娘',\n",
       " '我很好，谢谢，我爱你',\n",
       " '大象之歌',\n",
       " '痞子英雄2：黎明升起',\n",
       " '小叮当：永无兽传奇',\n",
       " '10年计划',\n",
       " '鬼驱人',\n",
       " '无赖汉',\n",
       " 'ST 红白的搜查档案',\n",
       " '行过死荫之地',\n",
       " '灭绝：丧尸屠城',\n",
       " '仲夏夜魔法',\n",
       " '爸爸的假期',\n",
       " '逆转胜',\n",
       " '今天的恋爱',\n",
       " '男人女人和孩子',\n",
       " '丧家之女',\n",
       " '触不可及',\n",
       " '丑女也有春天',\n",
       " '鲁斯和亚历克斯',\n",
       " '摇滚英雄',\n",
       " '尚衣院',\n",
       " '乐高DC超级英雄：正义联盟大战异魔联盟',\n",
       " '想爱就爱2.5',\n",
       " '四个月亮',\n",
       " '惊天绑架团',\n",
       " '石榴坡的复仇',\n",
       " '如此美好',\n",
       " '王牌',\n",
       " '僵尸来袭',\n",
       " '喧嚣贵族',\n",
       " '社交恐惧症',\n",
       " '神探驾到',\n",
       " '独自夜归的女孩',\n",
       " '阴阳先生',\n",
       " '小心许愿',\n",
       " '美丽谎言',\n",
       " '致命弯道6：终极审判',\n",
       " '温哥华的朝日',\n",
       " '刺客学妹',\n",
       " '纯真时代',\n",
       " '全能囧爸',\n",
       " '杀了我三次',\n",
       " '女生宿舍',\n",
       " '戴维克罗的恋爱和魔法',\n",
       " '陌生之地',\n",
       " '亚马逊萌猴奇遇记',\n",
       " '我们是兄弟',\n",
       " '爱与慈悲',\n",
       " '东京婚约',\n",
       " '二龙湖浩哥之狂暴之路',\n",
       " '林荫大道',\n",
       " '人狼游戏2：野兽阵营',\n",
       " '蝙蝠侠无极限：怪兽来袭',\n",
       " '后裔',\n",
       " '柔浪',\n",
       " '环城七十里',\n",
       " '无敌双环枪',\n",
       " '再见歌舞伎町',\n",
       " '加班遇到鬼',\n",
       " '法国缉毒风云',\n",
       " '真爱',\n",
       " '成人初学者',\n",
       " '包法利夫人',\n",
       " '新包法利夫人',\n",
       " '有我在这里',\n",
       " '丧尸围城：瞭望塔',\n",
       " '爱，藏起来',\n",
       " '危楼愚夫',\n",
       " '活埋前女友',\n",
       " '晚安妈咪',\n",
       " '御宅大冒险',\n",
       " 'X加Y',\n",
       " '不凡之路',\n",
       " '人质',\n",
       " '杀手女教师',\n",
       " '艺术大师',\n",
       " '亲子饭',\n",
       " '猫和老鼠：间谍使命',\n",
       " '善意杀戮',\n",
       " '妈咪侠',\n",
       " '理发师',\n",
       " '金箍棒传奇2：沙僧的逆袭',\n",
       " '美的统治',\n",
       " '庄稼之岛',\n",
       " '神在巴厘岛',\n",
       " '生命如此美好',\n",
       " '情事',\n",
       " '聋哑部落',\n",
       " '重拾人生',\n",
       " '东京难民',\n",
       " '百货战警2',\n",
       " '曼戈霍恩',\n",
       " '西游记之大圣归来',\n",
       " '日日摇滚',\n",
       " '花葬',\n",
       " '宝藏猎人久美子',\n",
       " '使命召唤',\n",
       " '灯光之外',\n",
       " '危险的见面礼2',\n",
       " '小黄人大眼萌',\n",
       " '我的男友和狗',\n",
       " '陡岸凶杀案',\n",
       " '中国城',\n",
       " '第二次爱你',\n",
       " '你爱的某人',\n",
       " '枪长莫及',\n",
       " '希波克拉底',\n",
       " '地狱奶奶',\n",
       " '终结者：创世纪',\n",
       " '年轻时候',\n",
       " '卡贾基',\n",
       " '把爸爸借给你',\n",
       " '蝙蝠侠无极限：动物本能',\n",
       " '点对点',\n",
       " '拼凑梦想',\n",
       " '仅此一夜',\n",
       " '恋恋如歌',\n",
       " '幸存者',\n",
       " '商务囧途',\n",
       " '远离人迹',\n",
       " '起死回生',\n",
       " '编剧情缘',\n",
       " '野狗们',\n",
       " '杀人依赖',\n",
       " '欢迎来到我的世界',\n",
       " '旧情',\n",
       " '只想和你在一起',\n",
       " '蜩之记',\n",
       " '不是冤家不聚头',\n",
       " '宝贝',\n",
       " '我的神烦腐妈',\n",
       " '朝鲜名侦探：奴隶的女儿',\n",
       " '阿斯特里克斯历险记：诸神之宫殿',\n",
       " '在我走之前',\n",
       " '真实',\n",
       " '诉讼',\n",
       " '暧昧不明关系研究学会',\n",
       " '世纪审判',\n",
       " '幸运情人草',\n",
       " '白色上帝',\n",
       " '人皮交易',\n",
       " '立体声',\n",
       " '爱情碎片',\n",
       " '温暖渐冻心',\n",
       " '感受大海的时刻',\n",
       " '想飞',\n",
       " '天师斗僵尸',\n",
       " '不可思议的海岸物语',\n",
       " '心脏移植医师',\n",
       " '伪造者',\n",
       " '失魂记忆',\n",
       " '侠僧探案传奇之将军府',\n",
       " '侠僧探案传奇之催命符',\n",
       " '侠僧探案传奇之开封府',\n",
       " '苹果恋爱多',\n",
       " '葡萄的眼泪',\n",
       " '公平竞赛',\n",
       " '侠僧探案传奇之醉玲珑',\n",
       " '侠僧探案传奇之洛阳花会',\n",
       " '解除好友',\n",
       " '爱在初春惊变时',\n",
       " '真英雄',\n",
       " '廷巴克图',\n",
       " '临时保姆',\n",
       " '德水里五兄弟',\n",
       " '侠僧探案传奇之大兴赌坊',\n",
       " '严惩',\n",
       " '男孩遇见女孩',\n",
       " '回光奏鸣曲',\n",
       " '甜蜜地狱之家',\n",
       " '海军陆战队员4',\n",
       " '侠僧探案传奇之白马镖局',\n",
       " '业内前五',\n",
       " '最后的骑士',\n",
       " '迷河',\n",
       " '侠僧探案传奇之王陵之谜',\n",
       " '太阳坐落之处',\n",
       " '少年轻狂',\n",
       " '侠僧探案传奇之大夜叉',\n",
       " '寒枝雀静',\n",
       " '它在身后',\n",
       " '荒野',\n",
       " '爱情攻略',\n",
       " '被舍弃的人们',\n",
       " '时光穿梭',\n",
       " '风暴之土',\n",
       " '致命追踪',\n",
       " '赌棍',\n",
       " '上帝难为',\n",
       " '阿提克斯研究所',\n",
       " '野鸡杀手',\n",
       " '追债大乱斗',\n",
       " '遭难者们',\n",
       " '吉米的舞厅',\n",
       " '美好世界终结时',\n",
       " '浴血华沙',\n",
       " '惊情谍变',\n",
       " '河畔的朔子',\n",
       " '失踪顺序',\n",
       " '诺曼人：维京传奇',\n",
       " '海洋之歌',\n",
       " '赤足',\n",
       " '黑手党只在夏天杀人',\n",
       " '黑海夺金',\n",
       " '生活伴侣',\n",
       " '行动代号：孙中山',\n",
       " '大喜临门',\n",
       " '食女',\n",
       " '伊朗式分手',\n",
       " '克莉丝堤：杀人网站',\n",
       " '迷失课后',\n",
       " '自由之丘',\n",
       " '骡子',\n",
       " '低入尘埃',\n",
       " '艾尔莎与弗雷德',\n",
       " '思春期游戏',\n",
       " '小森林 夏秋篇',\n",
       " '生活艰难也许快乐',\n",
       " '基隆',\n",
       " '我的男人',\n",
       " '老木逢春',\n",
       " '蜜月重温',\n",
       " '寻找幸福的赫克托',\n",
       " '大人不及格',\n",
       " '热血男人帮',\n",
       " '荒蛮故事',\n",
       " '奇怪的猫咪',\n",
       " '可爱老女人',\n",
       " '圣餐',\n",
       " '热血之路',\n",
       " '鳄鱼的黄眼睛',\n",
       " '鲁邦三世',\n",
       " '玫瑰香水',\n",
       " '早熟',\n",
       " '海豚的故事2',\n",
       " '蛋糕',\n",
       " '新年行动',\n",
       " '隔壁的男孩',\n",
       " '迷失1971',\n",
       " '澳门风云2',\n",
       " '血色孤语',\n",
       " '我的独裁者',\n",
       " '侠僧探案传奇之聚义钱庄',\n",
       " '顶级较量',\n",
       " '恶梦小姐 梦影版',\n",
       " '狼图腾',\n",
       " '东京暴族',\n",
       " '怒火保镖',\n",
       " '扑通扑通我的人生',\n",
       " '单身派对',\n",
       " '太平洋幽灵',\n",
       " '一曲倾情',\n",
       " '共犯',\n",
       " '杀死信使',\n",
       " '背负春天',\n",
       " '卒迹',\n",
       " '呼吸',\n",
       " '杀回归家路',\n",
       " '女儿国的杰基',\n",
       " '扑克之夜',\n",
       " '亚历山大和他最糟糕的一天',\n",
       " '米斯特和皮特必败',\n",
       " '幕末高校生',\n",
       " '在我消失前',\n",
       " '鸟瞰人生',\n",
       " '冰毒',\n",
       " '利维坦',\n",
       " '游客',\n",
       " '中间人2',\n",
       " '锡尔斯玛利亚',\n",
       " '危险的传言',\n",
       " '正义联盟：亚特兰蒂斯的宝座',\n",
       " '奇迹',\n",
       " '小乌龟是如何长大的',\n",
       " '金橘',\n",
       " '漫步夏威夷',\n",
       " '万能鉴定士Q：蒙娜丽莎之瞳',\n",
       " '第二扇窗',\n",
       " '被告护士',\n",
       " '爱很怪',\n",
       " '足不出户',\n",
       " '危险行为',\n",
       " '狙击精英：战纪',\n",
       " '近距离击杀',\n",
       " '冷库',\n",
       " '女子战队',\n",
       " '狐狸猎手',\n",
       " '意大利之旅',\n",
       " '枪之子',\n",
       " '杀妻同盟军',\n",
       " '他和她的孤独情事',\n",
       " '一千次晚安',\n",
       " '骄傲',\n",
       " '危险藏匿',\n",
       " '透纳先生',\n",
       " '晴天霹雳',\n",
       " '长牙',\n",
       " '吸血鬼生活',\n",
       " '幽暗山谷',\n",
       " '边境',\n",
       " '圣人文森特',\n",
       " '爱要来了',\n",
       " '再见语言',\n",
       " '魂断布宜诺斯艾利斯',\n",
       " '寻找隐世快乐',\n",
       " '罪恶赎金',\n",
       " '慢放镜头',\n",
       " '猫和老鼠：迷失之龙',\n",
       " '哆啦A梦：伴我同行',\n",
       " '女子学校拷问部',\n",
       " '依然爱丽丝',\n",
       " '夜间飞行',\n",
       " 'I型起源',\n",
       " '冬眠',\n",
       " '鸣梁海战',\n",
       " '大峰祖师',\n",
       " '美满姻缘',\n",
       " '决胜巅峰',\n",
       " '超高速！ 参勤交代',\n",
       " '泳队惊魂',\n",
       " '致命录像带3：病毒',\n",
       " '嫉妒',\n",
       " '只要你说你爱我',\n",
       " '弹窗惊魂',\n",
       " '救世',\n",
       " '我们的家族',\n",
       " '肖申克的救赎',\n",
       " '盗梦空间',\n",
       " '这个杀手不太冷',\n",
       " '阿甘正传',\n",
       " '霸王别姬',\n",
       " '三傻大闹宝莱坞',\n",
       " '千与千寻',\n",
       " '美丽人生',\n",
       " '泰坦尼克号',\n",
       " '海上钢琴师',\n",
       " '机器人总动员',\n",
       " '少年派的奇幻漂流',\n",
       " '忠犬八公的故事',\n",
       " '辛德勒的名单',\n",
       " '大话西游之大圣娶亲',\n",
       " '放牛班的春天',\n",
       " '触不可及',\n",
       " '怦然心动',\n",
       " '当幸福来敲门',\n",
       " '龙猫',\n",
       " '楚门的世界',\n",
       " '搏击俱乐部',\n",
       " '教父',\n",
       " 'V字仇杀队',\n",
       " '大话西游之月光宝盒',\n",
       " '飞屋环游记',\n",
       " '疯狂原始人',\n",
       " '让子弹飞',\n",
       " '无间道',\n",
       " '天堂电影院',\n",
       " '蝙蝠侠：黑暗骑士',\n",
       " '指环王3：王者无敌',\n",
       " '天空之城',\n",
       " '罗马假日',\n",
       " '十二怒汉',\n",
       " '两杆大烟枪',\n",
       " '鬼子来了',\n",
       " '天使爱美丽',\n",
       " '窃听风暴',\n",
       " '七宗罪',\n",
       " '乱世佳人',\n",
       " '美丽心灵',\n",
       " '致命魔术',\n",
       " '剪刀手爱德华',\n",
       " '飞越疯人院',\n",
       " '被嫌弃的松子的一生',\n",
       " '闻香识女人',\n",
       " '指环王1：魔戒再现',\n",
       " '活着',\n",
       " '指环王2：双塔奇兵',\n",
       " '阿凡达',\n",
       " '本杰明·巴顿奇事',\n",
       " '神偷奶爸',\n",
       " '哈尔的移动城堡',\n",
       " '阳光姐妹淘',\n",
       " '蝴蝶效应',\n",
       " '情书',\n",
       " '死亡诗社',\n",
       " '禁闭岛',\n",
       " '西西里的美丽传说',\n",
       " '低俗小说',\n",
       " '恐怖直播',\n",
       " '钢琴家',\n",
       " '沉默的羔羊',\n",
       " '驯龙高手',\n",
       " '狩猎',\n",
       " '黑客帝国',\n",
       " '教父2',\n",
       " '致命ID',\n",
       " '饮食男女',\n",
       " '狮子王',\n",
       " '美国往事',\n",
       " '时空恋旅人',\n",
       " '告白',\n",
       " '黑天鹅',\n",
       " '射雕英雄传之东成西就',\n",
       " '入殓师',\n",
       " '勇敢的心',\n",
       " '心灵捕手',\n",
       " '加勒比海盗',\n",
       " '杀人回忆',\n",
       " '重庆森林',\n",
       " '断背山',\n",
       " '玛丽和马克思',\n",
       " '拯救大兵瑞恩',\n",
       " '7号房的礼物',\n",
       " '第六感',\n",
       " '再次出发之纽约遇见你',\n",
       " '阳光灿烂的日子',\n",
       " '岁月神偷',\n",
       " '贫民窟的百万富翁',\n",
       " '大鱼',\n",
       " '哈利·波特与死亡圣器(下)',\n",
       " '源代码',\n",
       " '超脱',\n",
       " '爱在黎明破晓前',\n",
       " '记忆碎片',\n",
       " '蝙蝠侠：黑暗骑士崛起',\n",
       " '达拉斯买家俱乐部',\n",
       " '初恋这件小事',\n",
       " '那些年，我们一起追的女孩',\n",
       " '音乐之声',\n",
       " '猫鼠游戏',\n",
       " '幽灵公主',\n",
       " '甜蜜蜜',\n",
       " '春光乍泄',\n",
       " '恐怖游轮',\n",
       " '小鞋子',\n",
       " '怪兽电力公司',\n",
       " '爱在日落黄昏时',\n",
       " '借东西的小人阿莉埃蒂',\n",
       " '恋恋笔记本',\n",
       " '无敌破坏王',\n",
       " '哈利·波特与魔法石',\n",
       " '上帝之城',\n",
       " '唐伯虎点秋香',\n",
       " '倩女幽魂',\n",
       " '秒速5厘米',\n",
       " '被解救的姜戈',\n",
       " '穿条纹睡衣的男孩',\n",
       " '萤火之森',\n",
       " '真爱至上',\n",
       " '国王的演讲',\n",
       " '控方证人',\n",
       " '喜剧之王',\n",
       " '大闹天宫',\n",
       " '雨人',\n",
       " '香水',\n",
       " '菊次郎的夏天',\n",
       " '一一',\n",
       " '萤火虫之墓',\n",
       " '傲慢与偏见',\n",
       " '东邪西毒',\n",
       " '摩登时代',\n",
       " '风之谷',\n",
       " '幸福终点站',\n",
       " '爱在午夜降临前',\n",
       " '玩具总动员3',\n",
       " '碟中谍4',\n",
       " '速度与激情5',\n",
       " '冰川时代',\n",
       " '侧耳倾听',\n",
       " '悲惨世界',\n",
       " '谍影重重3',\n",
       " '末代皇帝',\n",
       " '疯狂的石头',\n",
       " '终结者2',\n",
       " '红辣椒',\n",
       " '穿越时空的少女',\n",
       " '穆赫兰道',\n",
       " '猜火车',\n",
       " '这个男人来自地球',\n",
       " '朗读者',\n",
       " '浪潮',\n",
       " '追随',\n",
       " '你看起来好像很好吃',\n",
       " '花样年华',\n",
       " '神偷奶爸2',\n",
       " '人工智能',\n",
       " '青蛇',\n",
       " '英雄本色',\n",
       " '卢旺达饭店',\n",
       " '教父3',\n",
       " '燃情岁月',\n",
       " '喜宴',\n",
       " '谍影重重',\n",
       " '完美的世界',\n",
       " '纵横四海',\n",
       " '未麻的部屋',\n",
       " '一次别离',\n",
       " '七武士',\n",
       " '两小无猜',\n",
       " '复仇者联盟',\n",
       " '罗生门',\n",
       " '撞车',\n",
       " '无耻混蛋',\n",
       " '我是山姆',\n",
       " '大卫·戈尔的一生',\n",
       " '阿飞正传',\n",
       " '变脸',\n",
       " '月球',\n",
       " '谍影重重2',\n",
       " '虎口脱险',\n",
       " '战争之王',\n",
       " '新龙门客栈',\n",
       " '海盗电台',\n",
       " '假如爱有天意',\n",
       " '魔女宅急便',\n",
       " '曾经',\n",
       " '霍比特人1：意外之旅',\n",
       " '黑客帝国3：矩阵革命',\n",
       " '美国丽人',\n",
       " '梦之安魂曲',\n",
       " '云图',\n",
       " '发条橙',\n",
       " 'E.T. 外星人',\n",
       " '蓝色大门',\n",
       " '千钧一发',\n",
       " '英国病人',\n",
       " '东京物语',\n",
       " '荒野生存',\n",
       " '和莎莫的500天',\n",
       " '志明与春娇',\n",
       " '魂断蓝桥',\n",
       " '忠犬八公物语',\n",
       " '非常嫌疑犯',\n",
       " '可可西里',\n",
       " '怪兽大学',\n",
       " '逃离德黑兰',\n",
       " '爱在暹罗',\n",
       " '赛德克·巴莱',\n",
       " '勇士',\n",
       " '我的野蛮女友',\n",
       " '里约大冒险',\n",
       " '开心家族',\n",
       " '社交网络',\n",
       " '遗愿清单',\n",
       " '刺猬的优雅',\n",
       " '偷拐抢骗',\n",
       " '地球上的星星',\n",
       " '荒岛余生',\n",
       " '勇闯夺命岛',\n",
       " '叫我第一名',\n",
       " '夜访吸血鬼',\n",
       " '血钻',\n",
       " '中国合伙人',\n",
       " '金陵十三钗',\n",
       " '惊魂记',\n",
       " '桃姐',\n",
       " '地心引力',\n",
       " '听说',\n",
       " '雨中曲',\n",
       " '阿黛尔的生活',\n",
       " '无间道2',\n",
       " '穿普拉达的女王',\n",
       " '末路狂花',\n",
       " '功夫熊猫2',\n",
       " 'X战警：第一战',\n",
       " '绿里奇迹',\n",
       " '登堂入室',\n",
       " '金福南杀人事件始末',\n",
       " '东邪西毒：终极版',\n",
       " '上帝也疯狂',\n",
       " '卡萨布兰卡',\n",
       " '碧海蓝天',\n",
       " '暖暖内含光',\n",
       " '枪火',\n",
       " '孤儿',\n",
       " '2001太空漫游',\n",
       " '第九区',\n",
       " '风声',\n",
       " '牯岭街少年杀人事件',\n",
       " '钢的琴',\n",
       " '人再囧途之泰囧',\n",
       " '麦兜故事',\n",
       " '黄金三镖客',\n",
       " '城市之光',\n",
       " '色，戒',\n",
       " '飓风营救',\n",
       " '我爱你',\n",
       " '黑客帝国2：重装上阵',\n",
       " '不一样的天空',\n",
       " '廊桥遗梦',\n",
       " '一天',\n",
       " '老男孩',\n",
       " '了不起的盖茨比',\n",
       " '九品芝麻官',\n",
       " '变形金刚',\n",
       " '一代宗师',\n",
       " '导盲犬小Q',\n",
       " '巴黎淘气帮',\n",
       " '龙纹身的女孩',\n",
       " '僵尸新娘',\n",
       " '杀死比尔',\n",
       " '坠入',\n",
       " '蝴蝶',\n",
       " '猩球崛起',\n",
       " '哪吒闹海',\n",
       " '神探',\n",
       " '横道世之介',\n",
       " '伴我同行',\n",
       " '我在伊朗长大',\n",
       " '百万美元宝贝',\n",
       " '追击者',\n",
       " '千年女优',\n",
       " '燕尾蝶',\n",
       " '黑鹰坠落',\n",
       " '铁甲钢拳',\n",
       " '午夜巴黎',\n",
       " '海底总动员',\n",
       " '嫌疑人X的献身',\n",
       " '盗钥匙的方法',\n",
       " '阳光小美女',\n",
       " '北京遇上西雅图',\n",
       " '他其实没那么喜欢你',\n",
       " '万箭穿心',\n",
       " '悲情城市',\n",
       " '加勒比海盗2：聚魂棺',\n",
       " '碟中谍',\n",
       " '环太平洋',\n",
       " '黑暗面',\n",
       " '了不起的狐狸爸爸',\n",
       " '角斗士',\n",
       " '洛城机密',\n",
       " '狗镇',\n",
       " '爱·回家',\n",
       " '蝙蝠侠：侠影之谜',\n",
       " '八月迷情',\n",
       " '中央车站',\n",
       " '悬崖上的金鱼姬',\n",
       " '国产凌凌漆',\n",
       " '灿烂人生',\n",
       " '哈利·波特与密室',\n",
       " '惊天魔盗团',\n",
       " '黄海',\n",
       " '赛德克·巴莱(上)：太阳旗',\n",
       " '功夫熊猫',\n",
       " '新世界',\n",
       " '大独裁者',\n",
       " '一级恐惧',\n",
       " '最佳出价',\n",
       " '星际迷航：暗黑无界',\n",
       " '盲井',\n",
       " '罗拉快跑',\n",
       " '跳出我天地',\n",
       " '后天',\n",
       " '弱点',\n",
       " '2012',\n",
       " '出租车司机',\n",
       " '成为简·奥斯汀',\n",
       " '壁花少年',\n",
       " '暗战',\n",
       " '美食总动员',\n",
       " '雏菊',\n",
       " '功夫',\n",
       " '无姓之人',\n",
       " '步履不停',\n",
       " '万能钥匙',\n",
       " '东京教父',\n",
       " '终结者',\n",
       " '小鬼当家',\n",
       " '失恋33天',\n",
       " '马达加斯加3',\n",
       " '钢铁侠',\n",
       " '心慌方',\n",
       " '换子疑云',\n",
       " '甲方乙方',\n",
       " '蒂凡尼的早餐',\n",
       " '时时刻刻',\n",
       " '落水狗',\n",
       " '攻壳机动队',\n",
       " '狼的孩子雨和雪',\n",
       " '胭脂扣',\n",
       " '生活多美好',\n",
       " '冰川时代4',\n",
       " '小岛惊魂',\n",
       " '花与爱丽丝',\n",
       " '十二猴子',\n",
       " '逆光飞翔',\n",
       " '土拨鼠之日',\n",
       " '我是传奇',\n",
       " '恋恋风尘',\n",
       " '战马',\n",
       " '诺丁山',\n",
       " '疯狂约会美丽都',\n",
       " 'K星异客',\n",
       " '赛德克·巴莱(下)：彩虹桥',\n",
       " '哈利·波特与阿兹卡班的囚徒',\n",
       " '玩具总动员',\n",
       " '春夏秋冬又一春',\n",
       " '查理和巧克力工厂',\n",
       " '侏罗纪公园',\n",
       " '莫扎特传',\n",
       " '魔发奇缘',\n",
       " '那山那人那狗',\n",
       " '为奴十二载',\n",
       " '加勒比海盗3：世界的尽头',\n",
       " '兵临城下',\n",
       " '相助',\n",
       " '黑衣人',\n",
       " '朱诺',\n",
       " '西雅图未眠夜',\n",
       " '初恋50次',\n",
       " '我们俩',\n",
       " '人鬼情未了',\n",
       " '童年往事',\n",
       " '编舟记',\n",
       " '迷雾',\n",
       " '沉静如海',\n",
       " '速度与激情6',\n",
       " '起风了',\n",
       " '再见列宁',\n",
       " '隐秘而伟大',\n",
       " '与狼共舞',\n",
       " '乌云背后的幸福线',\n",
       " '孤胆特工',\n",
       " '精英部队2：大敌当前',\n",
       " '红猪',\n",
       " '天书奇谭',\n",
       " '笑傲江湖2：东方不败',\n",
       " '红高粱',\n",
       " '冰川时代3',\n",
       " '激战',\n",
       " '热血警探',\n",
       " '闪灵',\n",
       " '独自等待',\n",
       " '爱',\n",
       " '钢铁侠3',\n",
       " '李米的猜想',\n",
       " '回到未来',\n",
       " '推手',\n",
       " '卧虎藏龙',\n",
       " '月升王国',\n",
       " '费城故事',\n",
       " '哈利·波特与火焰杯',\n",
       " '内布拉斯加',\n",
       " '麦兜当当伴我心',\n",
       " '食神',\n",
       " '你丫闭嘴！',\n",
       " '狙击电话亭',\n",
       " '赎罪',\n",
       " '单身男子',\n",
       " '大红灯笼高高挂',\n",
       " '超时空接触',\n",
       " '和声',\n",
       " '空中监狱',\n",
       " '人在囧途',\n",
       " ...]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(df['title'].values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies = list(df['title'].values)\n",
    "lengthes = list(df['length'].values)\n",
    "urls = list(df['url'].values)\n",
    "rates = list(df['rate'].values)\n",
    "movie_ids = [i for i in range(len(movies))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4587, 4587, 4587, 4587, 4587)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(movie_ids),len(lengthes),len(movies),len(urls),len(rates)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>id</th>\n",
       "      <th>url</th>\n",
       "      <th>rate</th>\n",
       "      <th>length</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>我是路人甲</td>\n",
       "      <td>0</td>\n",
       "      <td>http://movie.douban.com/subject/25746375/</td>\n",
       "      <td>7.4</td>\n",
       "      <td>134.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>铁拳</td>\n",
       "      <td>1</td>\n",
       "      <td>http://movie.douban.com/subject/5446197/</td>\n",
       "      <td>7.1</td>\n",
       "      <td>123.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>我们梦中见</td>\n",
       "      <td>2</td>\n",
       "      <td>http://movie.douban.com/subject/25885212/</td>\n",
       "      <td>7.6</td>\n",
       "      <td>92.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>少年透明人</td>\n",
       "      <td>3</td>\n",
       "      <td>http://movie.douban.com/subject/25728581/</td>\n",
       "      <td>6.6</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>撒迦利亚</td>\n",
       "      <td>4</td>\n",
       "      <td>http://movie.douban.com/subject/5156558/</td>\n",
       "      <td>6.0</td>\n",
       "      <td>95.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4582</th>\n",
       "      <td>幽灵世界</td>\n",
       "      <td>4582</td>\n",
       "      <td>http://movie.douban.com/subject/1304868/</td>\n",
       "      <td>7.9</td>\n",
       "      <td>111.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4583</th>\n",
       "      <td>吮拇指的人</td>\n",
       "      <td>4583</td>\n",
       "      <td>http://movie.douban.com/subject/1422954/</td>\n",
       "      <td>7.2</td>\n",
       "      <td>96.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4584</th>\n",
       "      <td>歌舞青春3：毕业季</td>\n",
       "      <td>4584</td>\n",
       "      <td>http://movie.douban.com/subject/2215609/</td>\n",
       "      <td>7.3</td>\n",
       "      <td>112.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4585</th>\n",
       "      <td>大河恋</td>\n",
       "      <td>4585</td>\n",
       "      <td>http://movie.douban.com/subject/1292718/</td>\n",
       "      <td>8.4</td>\n",
       "      <td>123.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4586</th>\n",
       "      <td>青春年少</td>\n",
       "      <td>4586</td>\n",
       "      <td>http://movie.douban.com/subject/1296835/</td>\n",
       "      <td>7.9</td>\n",
       "      <td>93.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4587 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           name    id                                        url  rate  length\n",
       "0         我是路人甲     0  http://movie.douban.com/subject/25746375/   7.4   134.0\n",
       "1            铁拳     1   http://movie.douban.com/subject/5446197/   7.1   123.0\n",
       "2         我们梦中见     2  http://movie.douban.com/subject/25885212/   7.6    92.0\n",
       "3         少年透明人     3  http://movie.douban.com/subject/25728581/   6.6   100.0\n",
       "4          撒迦利亚     4   http://movie.douban.com/subject/5156558/   6.0    95.0\n",
       "...         ...   ...                                        ...   ...     ...\n",
       "4582       幽灵世界  4582   http://movie.douban.com/subject/1304868/   7.9   111.0\n",
       "4583      吮拇指的人  4583   http://movie.douban.com/subject/1422954/   7.2    96.0\n",
       "4584  歌舞青春3：毕业季  4584   http://movie.douban.com/subject/2215609/   7.3   112.0\n",
       "4585        大河恋  4585   http://movie.douban.com/subject/1292718/   8.4   123.0\n",
       "4586       青春年少  4586   http://movie.douban.com/subject/1296835/   7.9    93.0\n",
       "\n",
       "[4587 rows x 5 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entity_movies = pd.DataFrame({'name':movies,'id':movie_ids,'url':urls,'rate':rates,'length':lengthes})\n",
    "entity_movies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "entity_movies.to_csv('./data/entities/movies.csv',index = None,encoding = 'utf8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "合并前人物个数：48617\n",
      "合并后人物个数：22937\n"
     ]
    }
   ],
   "source": [
    "directors = list(df['director'].values)\n",
    "composers = list(df['composer'].values)\n",
    "actors = list(df['actor'].values)\n",
    "people = []\n",
    "for i in directors:\n",
    "    if i:\n",
    "        people.extend(i)\n",
    "for j in composers:\n",
    "    if j:\n",
    "        people.extend(j)\n",
    "for k in actors:\n",
    "    if k:\n",
    "        people.extend(k)\n",
    "print('合并前人物个数：'+str(len(people)))\n",
    "people = list(set(people))\n",
    "print('合并后人物个数：'+str(len(people)))\n",
    "person_ids = [n for n in range(len(people))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>伊藤兰</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>冰室冴子</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>乔·马辛吉尔</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Scott Thomas</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>乔伊·克莱默</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22932</th>\n",
       "      <td>哈尔·霍尔布鲁克</td>\n",
       "      <td>22932</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22933</th>\n",
       "      <td>水泽奈子</td>\n",
       "      <td>22933</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22934</th>\n",
       "      <td>吴迪</td>\n",
       "      <td>22934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22935</th>\n",
       "      <td>于嘉萌</td>\n",
       "      <td>22935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22936</th>\n",
       "      <td>David Warner</td>\n",
       "      <td>22936</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>22937 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               name     id\n",
       "0               伊藤兰      0\n",
       "1              冰室冴子      1\n",
       "2            乔·马辛吉尔      2\n",
       "3      Scott Thomas      3\n",
       "4            乔伊·克莱默      4\n",
       "...             ...    ...\n",
       "22932      哈尔·霍尔布鲁克  22932\n",
       "22933          水泽奈子  22933\n",
       "22934            吴迪  22934\n",
       "22935           于嘉萌  22935\n",
       "22936  David Warner  22936\n",
       "\n",
       "[22937 rows x 2 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entity_people = pd.DataFrame({'name':people,'id':person_ids})\n",
    "entity_people"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "entity_people.to_csv('./data/entities/people.csv',index = None,encoding = 'utf8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "mv_classes = df['category'].values\n",
    "classes = []\n",
    "for c in mv_classes:\n",
    "    if c:\n",
    "        classes.extend(c)\n",
    "mv_classes = list(set(classes))\n",
    "class_ids = [n for n in range(len(mv_classes))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>情色</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>悬念</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>家庭</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>同性</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>战争</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>惊悚</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>武侠</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>爱情</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>喜剧</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>西部</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>历史</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>古装</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>惊栗</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>科幻</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>运动</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>恐怖</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>悬疑</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>犯罪</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>剧情</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>冒险</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>儿童</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>黑色电影</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>动作</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>音乐</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>鬼怪</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>灾难</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>奇幻</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>动画</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>传记</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>歌舞</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>荒诞</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    name  id\n",
       "0     情色   0\n",
       "1     悬念   1\n",
       "2     家庭   2\n",
       "3     同性   3\n",
       "4     战争   4\n",
       "5     惊悚   5\n",
       "6     武侠   6\n",
       "7     爱情   7\n",
       "8     喜剧   8\n",
       "9     西部   9\n",
       "10    历史  10\n",
       "11    古装  11\n",
       "12    惊栗  12\n",
       "13    科幻  13\n",
       "14    运动  14\n",
       "15    恐怖  15\n",
       "16    悬疑  16\n",
       "17    犯罪  17\n",
       "18    剧情  18\n",
       "19    冒险  19\n",
       "20    儿童  20\n",
       "21  黑色电影  21\n",
       "22    动作  22\n",
       "23    音乐  23\n",
       "24    鬼怪  24\n",
       "25    灾难  25\n",
       "26    奇幻  26\n",
       "27    动画  27\n",
       "28    传记  28\n",
       "29    歌舞  29\n",
       "30    荒诞  30"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entity_mv_classes = pd.DataFrame({'name':mv_classes,'id':class_ids})\n",
    "entity_mv_classes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "entity_mv_classes.to_csv('./data/entities/mv_classes.csv',index = None,encoding = 'utf8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "def clean_districts(dis_name):\n",
    "    if dis_name == 'United States of America_USA':\n",
    "        return '美国'\n",
    "    elif dis_name == 'Canada_Canada':\n",
    "        return '加拿大'\n",
    "    elif dis_name == 'United Kingdom_UK':\n",
    "        return '英国'\n",
    "    else:\n",
    "        result = re.sub('[^\\u4e00-\\u9fa5]+','',dis_name)\n",
    "        if result == '中国大陆':\n",
    "            result = '中国'\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'美国'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clean_districts('United States of America_USA')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "districts = df['district'].values\n",
    "districts_ = []\n",
    "for d in districts:\n",
    "    if d:\n",
    "        districts_.extend(d)\n",
    "for i in range(len(districts_)):\n",
    "    districts_[i] = clean_districts(districts_[i])\n",
    "districts = list(set(districts_))\n",
    "district_ids = [n for n in range(len(districts))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>墨西哥</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>波多黎各</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>荷兰</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>马来西亚</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>西班牙</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>意大利</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>乌兹别克斯坦</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>希腊</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>挪威</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>越南</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>75 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      name  id\n",
       "0      墨西哥   0\n",
       "1     波多黎各   1\n",
       "2       荷兰   2\n",
       "3     马来西亚   3\n",
       "4      西班牙   4\n",
       "..     ...  ..\n",
       "70     意大利  70\n",
       "71  乌兹别克斯坦  71\n",
       "72      希腊  72\n",
       "73      挪威  73\n",
       "74      越南  74\n",
       "\n",
       "[75 rows x 2 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entity_districts = pd.DataFrame({'name':districts,'id':district_ids})\n",
    "entity_districts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "entity_districts.to_csv('./data/entities/districts.csv',index = None,encoding = 'utf8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['English',\n",
       " 'Assyrian Neo-Aramaic',\n",
       " 'Armenian',\n",
       " 'Tatar',\n",
       " 'Hawaiian',\n",
       " 'Shanghainese',\n",
       " 'Belarusian',\n",
       " 'Ungwatsi',\n",
       " 'Ukrainian',\n",
       " 'Klingon',\n",
       " 'Swahili',\n",
       " 'Galician',\n",
       " 'Icelandic',\n",
       " 'Punjabi']"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "languages = df['language'].values\n",
    "languages_ = []\n",
    "for d in languages:\n",
    "    if d:\n",
    "        languages_.extend(d)\n",
    "eng = []\n",
    "for l in languages_:\n",
    "    if not re.sub('[^\\u4e00-\\u9fa5]+','',l):\n",
    "        eng.append(l)\n",
    "list(set(eng))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "def clean_language(lan_name):\n",
    "    eng_name = ['Belarusian','Armenian','English','Icelandic',\n",
    "                'Punjabi','Swahili','Galician','Shanghainese','Klingon',\n",
    "                'Ungwatsi','Hawaiian','Tatar','Assyrian Neo-Aramaic','Ukrainian']\n",
    "    chi_name = ['比利时语','亚美尼亚语','英语','冰岛语',\n",
    "                '旁遮普语','斯瓦希里语','加利西亚语','上海话','克林贡语',\n",
    "                '翁瓦西','夏威夷语','鞑靼语','亚述语新阿拉姆语','乌克兰语']\n",
    "    if lan_name in eng_name:\n",
    "        return chi_name[eng_name.index(lan_name)]\n",
    "    else:\n",
    "        return re.sub('[^\\u4e00-\\u9fa5]+','',lan_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>加泰罗尼亚语</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>泰米尔语</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>保定话</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>毛利语</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>萨卡语</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>173</th>\n",
       "      <td>阿布哈兹语</td>\n",
       "      <td>173</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>174</th>\n",
       "      <td>缅甸语</td>\n",
       "      <td>174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>175</th>\n",
       "      <td>罗马尼亚语</td>\n",
       "      <td>175</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>176</th>\n",
       "      <td>客家语</td>\n",
       "      <td>176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>177</th>\n",
       "      <td>云南方言</td>\n",
       "      <td>177</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>178 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       name   id\n",
       "0    加泰罗尼亚语    0\n",
       "1      泰米尔语    1\n",
       "2       保定话    2\n",
       "3       毛利语    3\n",
       "4       萨卡语    4\n",
       "..      ...  ...\n",
       "173   阿布哈兹语  173\n",
       "174     缅甸语  174\n",
       "175   罗马尼亚语  175\n",
       "176     客家语  176\n",
       "177    云南方言  177\n",
       "\n",
       "[178 rows x 2 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "languages = df['language'].values\n",
    "languages_ = []\n",
    "for d in languages:\n",
    "    if d:\n",
    "        languages_.extend(d)\n",
    "for i in range(len(languages_)):\n",
    "    languages_[i] = clean_language(languages_[i])\n",
    "languages = list(set(languages_))\n",
    "language_ids = [n for n in range(len(languages))]\n",
    "entity_languages = pd.DataFrame({'name':languages,'id':language_ids})\n",
    "entity_languages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "entity_languages.to_csv('./data/entities/languages.csv',index = None,encoding = 'utf8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "years = list(set(list(df['showtime'].values)))\n",
    "years_ = []\n",
    "for y in years:\n",
    "    if str(y)!='nan':\n",
    "        years_.append(str(int(y)))\n",
    "years = years_\n",
    "year_ids = [n for n in range(len(years))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1920',\n",
       " '1921',\n",
       " '1922',\n",
       " '1923',\n",
       " '1924',\n",
       " '1925',\n",
       " '1926',\n",
       " '1927',\n",
       " '1928',\n",
       " '1929',\n",
       " '1931',\n",
       " '1932',\n",
       " '1933',\n",
       " '1934',\n",
       " '1935',\n",
       " '1936',\n",
       " '1937',\n",
       " '1938',\n",
       " '1939',\n",
       " '1940',\n",
       " '1941',\n",
       " '1942',\n",
       " '1943',\n",
       " '1944',\n",
       " '1945',\n",
       " '1946',\n",
       " '1947',\n",
       " '1948',\n",
       " '1949',\n",
       " '1950',\n",
       " '1951',\n",
       " '1952',\n",
       " '1953',\n",
       " '1954',\n",
       " '1955',\n",
       " '1956',\n",
       " '1957',\n",
       " '1958',\n",
       " '1959',\n",
       " '1960',\n",
       " '1961',\n",
       " '1962',\n",
       " '1963',\n",
       " '1964',\n",
       " '1965',\n",
       " '1966',\n",
       " '1967',\n",
       " '1968',\n",
       " '1969',\n",
       " '1970',\n",
       " '1971',\n",
       " '1972',\n",
       " '1973',\n",
       " '1974',\n",
       " '1975',\n",
       " '1976',\n",
       " '1977',\n",
       " '1978',\n",
       " '1979',\n",
       " '1980',\n",
       " '1981',\n",
       " '1982',\n",
       " '1983',\n",
       " '1984',\n",
       " '1985',\n",
       " '1986',\n",
       " '1987',\n",
       " '1988',\n",
       " '1989',\n",
       " '1990',\n",
       " '1991',\n",
       " '1992',\n",
       " '1993',\n",
       " '1994',\n",
       " '1995',\n",
       " '1996',\n",
       " '1997',\n",
       " '1998',\n",
       " '1999',\n",
       " '2000',\n",
       " '2001',\n",
       " '2002',\n",
       " '2003',\n",
       " '2004',\n",
       " '2005',\n",
       " '2006',\n",
       " '2007',\n",
       " '2008',\n",
       " '2009',\n",
       " '2010',\n",
       " '2011',\n",
       " '2012',\n",
       " '2013',\n",
       " '2014',\n",
       " '2015']"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "years"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1920</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1921</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1922</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1923</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1924</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>2011</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>2012</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>2013</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>2014</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>2015</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>95 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    name  id\n",
       "0   1920   0\n",
       "1   1921   1\n",
       "2   1922   2\n",
       "3   1923   3\n",
       "4   1924   4\n",
       "..   ...  ..\n",
       "90  2011  90\n",
       "91  2012  91\n",
       "92  2013  92\n",
       "93  2014  93\n",
       "94  2015  94\n",
       "\n",
       "[95 rows x 2 columns]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entity_years = pd.DataFrame({'name':years,'id':year_ids})\n",
    "entity_years"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "entity_years.to_csv('./data/entities/years.csv',index = None,encoding = 'utf8')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###### 实体-实体 关系：\n",
    "###### 电影-导演-人名 d_d_r\n",
    "###### 电影-编剧-人名 d_b_r\n",
    "###### 电影-演员-人名 d_y_r\n",
    "###### 电影-类型-电影类型 d_l_d\n",
    "###### 电影-上映时间-年份 d_s_n\n",
    "###### 电影-上映地点-地点 d_s_d\n",
    "###### 电影-语言-语言 d_y_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "#movies\\people\\mv_classes\\districts\\languages\\years\n",
    "mov = list(df['title'].values)\n",
    "di = list(df['director'].values)\n",
    "com = list(df['composer'].values)\n",
    "act = list(df['actor'].values)\n",
    "cat = list(df['category'].values)\n",
    "lan = list(df['language'].values)\n",
    "dis = list(df['district'].values)\n",
    "sho = [] \n",
    "for i in list(df['showtime'].values):\n",
    "    if str(i)!='nan':\n",
    "        sho.append(str(int(i)))\n",
    "    else:\n",
    "        sho.append('')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "relations = []\n",
    "for i in range(len(mov)):\n",
    "    mov_id = movies.index(mov[i])\n",
    "    if di[i]:\n",
    "        for d in di[i]:\n",
    "            if d:\n",
    "                di_id = people.index(d)\n",
    "                relations.append((mov_id,'导演',di_id))\n",
    "    if com[i]:\n",
    "        for co in com[i]:\n",
    "            if co:\n",
    "                co_id = people.index(co)\n",
    "                relations.append((mov_id,'编剧',co_id))\n",
    "    if act[i]:\n",
    "        for ac in act[i]:\n",
    "            if ac:\n",
    "                ac_id = people.index(ac)\n",
    "                relations.append((mov_id,'演员',ac_id))\n",
    "    if cat[i]:\n",
    "        for ca in cat[i]:\n",
    "            if ca:\n",
    "                ca_id = mv_classes.index(ca)\n",
    "                relations.append((mov_id,'类型',ca_id))\n",
    "    if sho[i]:\n",
    "        sh_id = years.index(sho[i])\n",
    "        relations.append((mov_id,'上映时间',sh_id))\n",
    "    if dis[i]:\n",
    "        for dis_ in dis[i]:\n",
    "            if dis_:\n",
    "                dis_id = districts.index(clean_districts(dis_))\n",
    "                relations.append((mov_id,'上映地区',dis_id))\n",
    "    if lan[i]:\n",
    "        for la in lan[i]:\n",
    "            if la:\n",
    "                la_id = languages.index(clean_language(la))\n",
    "                relations.append((mov_id,'语言',la_id))\n",
    "\n",
    "relations = list(set(relations))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Entity1</th>\n",
       "      <th>Relation</th>\n",
       "      <th>Entity2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2694</td>\n",
       "      <td>编剧</td>\n",
       "      <td>6626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1163</td>\n",
       "      <td>语言</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3738</td>\n",
       "      <td>导演</td>\n",
       "      <td>21303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2640</td>\n",
       "      <td>演员</td>\n",
       "      <td>9903</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4014</td>\n",
       "      <td>演员</td>\n",
       "      <td>16694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77384</th>\n",
       "      <td>65</td>\n",
       "      <td>上映地区</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77385</th>\n",
       "      <td>1154</td>\n",
       "      <td>编剧</td>\n",
       "      <td>19790</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77386</th>\n",
       "      <td>3162</td>\n",
       "      <td>导演</td>\n",
       "      <td>21575</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77387</th>\n",
       "      <td>2665</td>\n",
       "      <td>演员</td>\n",
       "      <td>1147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77388</th>\n",
       "      <td>789</td>\n",
       "      <td>上映时间</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>77389 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       Entity1 Relation  Entity2\n",
       "0         2694       编剧     6626\n",
       "1         1163       语言       45\n",
       "2         3738       导演    21303\n",
       "3         2640       演员     9903\n",
       "4         4014       演员    16694\n",
       "...        ...      ...      ...\n",
       "77384       65     上映地区       45\n",
       "77385     1154       编剧    19790\n",
       "77386     3162       导演    21575\n",
       "77387     2665       演员     1147\n",
       "77388      789     上映时间       86\n",
       "\n",
       "[77389 rows x 3 columns]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e_r_e = pd.DataFrame(relations, columns=['Entity1', 'Relation','Entity2'])\n",
    "e_r_e"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "e_r_e.to_csv('./data/relations/triple.csv',index = None,encoding = 'utf8')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "kg_zhj",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
